package cn.com.api.controller;

import java.io.PrintWriter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.api.entity.ApiSmslog;
import cn.com.api.entity.ApiT_city;

import cn.com.api.service.ApiT_cityService;
import cn.com.api.service.ApiSmslogService;
import cn.com.util.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
@RequestMapping(Utils.SYS_API + "city/")
public class ApiT_cityController {
	@Autowired
	private ApiT_cityService apiT_cityService;
	@Autowired
	private ApiSmslogService apiSmslogService;

	//
	@RequestMapping("/findT_citysByIsOpen")
	public void findT_citysByIsOpen(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String is_open = request.getParameter("is_open");
		Map<String, Object> map = new HashMap<String, Object>();
		/*
		if (is_open.length() == 0)
			is_open = "1";
		*/	
		List<ApiT_city> list = apiT_cityService.findT_citys();

		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "查询成功！");
		map.put("datas", list);
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}

	//
	@RequestMapping("/findCitysIsOpen4erp")
	public void findCitysIsOpen4erp(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();

		List<ApiT_city> list = apiT_cityService.findT_citysByIsOpen(1);

		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "查询成功！");
		map.put("datas", list);
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}

	
	//
	@RequestMapping("/findT_citysLikeName")
	public void findT_citysLikeName(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String keyword = request.getParameter("keyword");

		Map<String, Object> map = new HashMap<String, Object>();

		List<ApiT_city> list = apiT_cityService.findT_citysLikeName(keyword);
		/*
		for(ApiT_city city : list){
			String is_open = String.valueOf(city.getIs_open());
		}
		*/
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "查询成功！");
		map.put("datas", list);
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}

}
